//
// Created by haoy on 2017/6/23.
//

#include "rtp/rtp_rtx.hpp"

#include "xcutil.h"

int RtpRtx::read(const uint8_t *data, int size) {
    // at least 2 bytes for osn
    if (size < 2) {
        return 0;
    }
    osn = be_get_u16(data);
    payload_size = size - 2;
    if (payload_size > 0) {
        payload = const_cast<uint8_t*>(data + 2);
    } else {
        payload = nullptr;
    }
    return size;
}

int RtpRtx::write(uint8_t *data, int size) const {
    if (size < 2 + payload_size) {
        return 0;
    }
    be_set_u16(osn, data);
    memcpy(data + 2, payload, payload_size);
    return 2 + payload_size;
}
